package com.tyd.cams;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.tyd.cams.entity.FanKabean;
import com.tyd.cams.utils.SPUtils;
import com.xuexiang.xui.widget.dialog.DialogLoader;
import com.xuexiang.xui.widget.dialog.strategy.impl.MaterialDialogStrategy;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import org.json.JSONObject;

import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import okhttp3.Call;

public class GuokaocxActivity extends AppCompatActivity {
    DialogLoader mDialogLoader = DialogLoader.getInstance().setIDialogStrategy(new MaterialDialogStrategy());

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guokaocx);
        findViewById(R.id.et_ks_name);
        findViewById(R.id.et_ks_zkzh);
    }

    /*n四六级成绩*/
    public void cet(View view) {
        EditText ksName = findViewById(R.id.et_ks_name);
        EditText ksZkzh = findViewById(R.id.et_ks_zkzh);
        String data = "CET_202012_DANGCI";
        new Thread(() -> OkHttpUtils.get()
//                + data+","+ksZkzh.getText().toString()+","+ksName.getText().toString()
                .url(SPUtils.getIP() + "/cet/cet4")
//                .addHeader("Host", SPUtils.getCETHost())
//                .addHeader("Referer", SPUtils.getCETReferer())
//                .addParams("data", data + "," + ksZkzh.getText().toString() + "," + ksName.getText().toString())
                .addHeader("Authorization", SPUtils.getToken())
                .addParams("ticketNumber", ksZkzh.getText().toString())
                .addParams("name", ksName.getText().toString())
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Toast.makeText(GuokaocxActivity.this, "查询四六级服务器超时", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        Log.i("获取的返回信息", response);
                    /*    String skh="(?<=\\()[^\\)]+";
                        Pattern pattern=Pattern.compile(skh);
                        Matcher matcher=pattern.matcher(response);*/

                        Gson son = new Gson();
                        Map slj = son.fromJson(response, Map.class);
                        mDialogLoader.showTipDialog(GuokaocxActivity.this,
                                R.drawable.cjcx,
                                slj.get("n") + "的四六级成绩",
                                "学校：" + slj.get("x") + "\n\n" + "四级成绩：" + slj.get("s"),
                                "确认",
                                (dialog, which) -> {
                                    //点击确认按钮后关闭提示框
                                    dialog.dismiss();
                                });
                        Log.i("四六级成绩", slj.toString());
                        //设置适配器
                    }
                })).start();

    }

    /*全国英语四六级等级考试：https://m7m3mw.smartapps.cn/pages/jiaoyu/cet/fillInfo/index*/
    public void PETS(View view) {
        String webUrl = "https://m7m3mw.smartapps.cn/pages/jiaoyu/cet/fillInfo/index";
        Intent intent = new Intent(GuokaocxActivity.this, GuokaoChenjiActivity.class).putExtra("url", webUrl);
        startActivity(intent);

    }

    /*中小学教师资格证考试*/
    public void NTCE(View view) {
        String webUrl = "https://m7m3mw.smartapps.cn/moduleB/jiaoyu/ntceGrade/fillInfo/index";
//        String webUrl = "https://m7m3mw.smartapps.cn/pages/fuwushouye/index?service_id=003";
                Intent intent = new Intent(GuokaocxActivity.this, GuokaoChenjiActivity.class).putExtra("url", webUrl);
        startActivity(intent);
    }

    /*少数民族汉语等级考试：https://m7m3mw.smartapps.cn/moduleB/jiaoyu/mhkGrade/fillInfo/index*/
    public void mhk(View view) {
        String webUrl = "https://m7m3mw.smartapps.cn/moduleB/jiaoyu/mhkGrade/fillInfo/index";
        Intent intent = new Intent(GuokaocxActivity.this, GuokaoChenjiActivity.class).putExtra("url", webUrl);
        startActivity(intent);
    }

    /*全国普通话水平测试考试：https://m7m3mw.smartapps.cn/pages/jiaoyu/putonghuaGrade/fillInfo/index*/
    public void NCRE(View view) {
        String webUrl = "https://m7m3mw.smartapps.cn/pages/jiaoyu/putonghuaGrade/fillInfo/index";
        Intent intent = new Intent(GuokaocxActivity.this, GuokaoChenjiActivity.class).putExtra("url", webUrl);
        startActivity(intent);
    }

    /*查询准考证号：http://cet-bm.neea.cn/Home/QueryTestTicket*/
    public void CCPT(View view) {
        String webUrl = "http://cet-bm.neea.cn/Home/QueryTestTicket";
        Intent intent = new Intent(GuokaocxActivity.this, GuokaoChenjiActivity.class).putExtra("url", webUrl);
        startActivity(intent);
    }
}